﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace SystemFrameWork
{
    public class ResourceManager
    {
        #region Resource Keys
        public static readonly string Title_MessageTitle = "Title_MessageTitle";
        #endregion

        #region Static Methods

        /// <summary>
        /// Get the string message from the resource file by key.
        /// </summary>
        /// <param name="key">key of the resource.</param>
        /// <returns></returns>
        public static string GetString(string key, params object[] parameters)
        {
            if (HttpContext.Current != null)
            {
                //if the request comes from web application.
                return StringHelper.GetStringValue(HttpContext.GetGlobalResourceObject("Pass", key), parameters);
            }
            else
            {
                //If the request for resource is from Unit Test.
                return key;
            }
        }

        /// <summary>
        /// Get the string message from the resource file by key.
        /// </summary>
        /// <param name="resourceFileName">resource file name</param>
        /// <param name="key">key of the resource (column name)</param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static string GetMenuString(string cultureName, string key, params object[] parameters)
        {
            if (HttpContext.Current != null)
            {
                //the vs.net IDE changes the dash "-" to "_" of the file name when create a new resource file,
                //so the code here has to replace the dash "-" with "_" in the parameter of Culture 
                string res = string.Format("PASSMenu{0}", cultureName).Replace("-", "_");
                //if the request comes from web application.
                return StringHelper.GetStringValue(HttpContext.GetGlobalResourceObject(@res, key), parameters);
            }
            else
            {
                //If the request for resource is from Unit Test.
                return key;
            }
        }

        /// <summary>
        /// Get the string message from the resource file by key.
        /// </summary>
        /// <param name="resourceFileName">resource file name</param>
        /// <param name="key">key of the resource (column name)</param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static string GetEmailTemplate(string cultureName, string fileName)
        {
            if (HttpContext.Current != null)
            {
                //the vs.net IDE changes the dash "-" to "_" of the file name when create a new resource file,
                //so the code here has to replace the dash "-" with "_" in the parameter of Culture 
                string res = fileName + "." + cultureName + ".htm";
                //if the request comes from web application.
                return res;
            }
            else
            {
                //If the request for resource is from Unit Test.
                return string.Empty;
            }
        }

        #endregion
    }
}
